package com.woniuxy.microorderserver.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.microcommonserver.bean.order_caize.OrderInfo;
import com.woniuxy.microcommonserver.pageHelper.PageRequest;
import com.woniuxy.microorderserver.mapper.OrderMapper;
import com.woniuxy.microorderserver.service.IOrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
@Transactional(readOnly = true)
@Service
public class OrderServiceImpl implements IOrderService {

    @Resource
    private OrderMapper orderMapper;



    /**
     * 根据用户id查询用户所有的订单
     * @param request
     * @param
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public PageInfo<OrderInfo> findOrderAllBySearch(PageRequest request, OrderInfo orderInfo) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->orderMapper.findOrderAllBySearch(request,orderInfo));
    }

    /**
     * 根据订单id删除订单
     * @param id
     * @return
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int delOrder(Long id) {
        return orderMapper.delOrder(id);
    }

    /**
     * 根据订单编号查看订单详情。订单信息。收货人信息
     */
    @Override
    public OrderInfo findOrderByOrderNum(Long orderNum) {
        return orderMapper.findOrderByOrderNum(orderNum);
    }
}
